<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
	"http://www.w3.org/TR/html4/strict.dtd">
<html>
	
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<title>Calendar Sample: Desktop</title>				
		<style type="text/css">
			@import "../themes/claro/Calendar.css";
			@import "calendar.css";
			@import "../../../dojo/resources/dojo.css";
			@import "../../../dijit/themes/dijit.css";
			@import "../../../dijit/themes/claro/claro.css";
		</style>			
	</head>
	
	<body class="claro">
		<script type="text/javascript" 
						data-dojo-config="async: true, parseOnLoad: true"
		 				src="../../../dojo/dojo.js"></script>
		
			<script type="text/javascript">

			require(["dojo/ready", "dojo/_base/lang", "dojo/_base/sniff", "dojo/_base/array", "dojo/_base/fx", "dojo/on", 
			         "dojo/date/locale", "dojo/parser",	"dojo/dom", "dojo/dom-construct",	"dojo/store/Memory", 
			         "dojo/store/Observable",	"dojox/calendar/Calendar", "dijit/Calendar",  "dijit/TitlePane", 
			         "dijit/layout/BorderContainer", "dijit/layout/ContentPane", "dijit/form/CheckBox", 
			         "dijit/form/TextBox", "dijit/form/DateTextBox", "dijit/form/TimeTextBox", 
			         "dijit/form/Button", "dijit/form/ComboBox", "dijit/Menu", "dijit/MenuItem"	],

				function(ready, lang, has, arr, fx, on, locale, parser, dom, domConstruct,
					Memory, Observable, Calendar){

					ready(function(){
					
						// Display different hint every 10 seconds 
											
						calendar.set("cssClassFunc", function(item){
							// Use custom css class on renderers depending of a parameter (calendar).							
							return item.calendar == "cal1" ? "Calendar1" : "Calendar2"
						});
						
						// Calendar model creation						
						var modelBase = [
							{day: 1, start: [10,0], duration: 1400},
							{day: 2, start: [10,30], duration: 120},
							{day: 2, start: [12,0], duration: 240},
							{day: 3, start: [6,0], duration: 180},
							{day: 3, start: [0,0], duration: 2880, allDay: true}
						];
						
						var someData = [];
												
						var startOfWeek = calendar.floorToWeek(new calendar.dateClassObj());
						
						for (var id=0; id<modelBase.length; id++) {
							var newObj = {
								id: id,
								summary: "New Event " + id,
								startTime: new calendar.dateClassObj(startOfWeek.getTime()),
								endTime: new calendar.dateClassObj(startOfWeek.getTime()),
								calendar: id%2 == 0 ? "cal1" : "cal2",
								allDay: modelBase[id].allDay
							};

							newObj.startTime = calendar.dateModule.add(newObj.startTime, "day", modelBase[id].day);
							newObj.startTime.setHours(modelBase[id].start[0]);
							newObj.startTime.setMinutes(modelBase[id].start[1]);

							newObj.endTime = calendar.dateModule.add(newObj.startTime, "minute", modelBase[id].duration);

							someData.push(newObj);
						}
						
						calendar.set("store", new Observable(new Memory({data: someData})));
						calendar.set("date", startOfWeek);									
						
						contextMenuDelete.on("click", function(){
							arr.forEach(calendar.selectedItems, function(item){
								calendar.store.remove(item.id);
							}); 							
						});
						
						
						var ss, se;
						calendar.on("itemEditBegin", function(e){
							// save initial values
							ss = calendar.newDate(e.item.startTime);
							se = calendar.newDate(e.item.endTime);
						});
						
						calendar.on("itemEditEnd", function(e){
							// a condition using properties of the store item and the render item
							if(e.storeItem.calendar == "cal2" && e.item.startTime.getHours() >= 13){
								// cancel default behavior (i.e. applying changes to store)
								e.preventDefault();
								
								// set the previously values to revert changes on the render item
								e.item.startTime = ss;
								e.item.endTime = se;
							} // default behavior for other use cases
						});

						
						// Hide loading panel when application is ready
						fx.fadeOut({
							node:"loadingPanel", 
							onEnd: function(node){
								node.parentNode.removeChild(node)
							}}).play(500);
						

					});
			});
			</script>
			
			<div id="loadingPanel" style="position:absolute;z-index:10;width:100%;height:100%;background:#ffffff">
				<span style="background: #DBEB8F;padding:2px">Loading...</span>
			</div>
			
			<div data-dojo-type="dijit.layout.BorderContainer" style="width:100%;height:100%" data-dojo-props="design:'sidebar', gutters:true" >
		    <div data-dojo-type="dijit.layout.ContentPane" data-dojo-props="splitter:false, region:'center'">
		        <div data-dojo-id="calendar" data-dojo-type="dojox.calendar.Calendar" 
					style="position:absolute;left:10px;top:10px;bottom:30px;right:10px">
					<div data-dojo-type="dijit.Menu" data-dojo-id="calendarContextMenu" style="display: none;">
		                <div data-dojo-type="dijit.MenuItem" data-dojo-id="contextMenuDelete" data-dojo-props="iconClass:'dijitIcon dijitIconDelete'">Delete</div>
		            </div>	
				</div>
				<div id="hint" style="position:absolute;left:10px;height:15px;bottom:10px;right:10px;color:#999;overflow:auto">Move a blue event after 1pm, gesture is canceled.</div>
		    </div>
		    
		</div>																		
						
	</body>
</html>
